package org.formal.system.config;


import java.util.Properties;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
//import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import tk.mybatis.spring.mapper.MapperScannerConfigurer;

/**
 * 数据源配置类
 * @author jiangyan
 *
 */
@Configuration
public class DruidConfig {

	@Bean
	public ServletRegistrationBean druidServlet() {

		ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),
				"/druid/*");
		// 登录查看信息的账号密码.

		servletRegistrationBean.addInitParameter("loginUsername", "admin");

		servletRegistrationBean.addInitParameter("loginPassword", "1");
		return servletRegistrationBean;
	}

	@Bean
	public FilterRegistrationBean filterRegistrationBean() {
		FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
		filterRegistrationBean.setFilter(new WebStatFilter());
		filterRegistrationBean.addUrlPatterns("/*");
		filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
		return filterRegistrationBean;
	}

	/**
	 * Mybatis通用Mapper配置UUID 
	 * @return
	 */
	@Bean
	public MapperScannerConfigurer mapperScannerConfigurer() {
		MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
		mapperScannerConfigurer.setBasePackage("org.formal.*.dao");
		Properties propertiesMapper = new Properties();
		// 主键UUID回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER)
		propertiesMapper.setProperty("ORDER", "BEFORE");
		mapperScannerConfigurer.setProperties(propertiesMapper);
		return mapperScannerConfigurer;
	}
	

}
